September 90 - Assertions in MacApp
Assertions in MacApp
James Plamondon
Have you ever loved someone you couldn't have? Someone of such rare grace, beauty,
and elegance that his or her charms were beyond the appreciation of many of your
peers, whose tastes, shall we say, were not nearly as refined and discriminating as
your own?
Such is my love affair with Bertrand Meyer's object-oriented language, Eiffel. Well
described in his book, Object-oriented Software Construction (Prentice-Hall, 1988),
Eiffel is a paragon of elegance, power, and simplicity. Every time I waste an hour
fighting Pascal's USES clause, or stuff some routine into UObject to get around single
inheritance, or write yet another list class (because TList only handles object
references), or consider (out of desperation, not desire) turning to C++, I long for
the simple solutions Eiffel would provide.
But my love is as hopeless as it is deep-there is, at the time of this writing, no
implementation of Eiffel available for the Mac. There's a stripped-down A/UX version
nearing completion, and a full Mac OS version planned for a January release-however,
these are still in vapor form. Until they solidify-and mature into the complete
implementations they almost certainly will not be, in their initial releases-my love
must remain unrequited, its fires banked, but still glowing.
Until then, I will continue to console myself with Object Pascal. There are three
reasons why I do so:
• Object Pascal has a sterling virtue that even Eiffel can't claim: it's the
lingua franca of MacApp.
• If you can't be with the one you love, baby love the one you're with!
• MacApp's comprehensive utilities mask some of Object Pascal's
deficiencies such that, if the bar's dark, the beer's cheap, and you squint a
little bit, Object Pascal can look just enough like Eiffel to get you interested.
I'm going to address one aspect of that resemblance in this annotated compilation of
MacApp.Tech$ links: assertions. An integral part of Eiffel, assertions are the means by
which the semantics of an abstract data type are enforced. For example, Eiffel's
preconditions (one kind of assertion) ensure that a method is never called with invalid
arguments. Likewise, postconditions ensure that a routine has always done what it was
supposed to have done before it returns. Loop variants and invariants ensure loop
termination. While not allowing the direct production of formal, mathematical proofs
directly from code, the Eiffel assertion mechanism is a powerful weapon in the
commercial programmer's arsenal against bugs.
Neither Object Pascal nor MacApp directly address these issues. However, hidden away
in the purdah of UMacAppUtilities, unmentioned, undocumented, and generally ignored,
are the seeds of an assertion mechanism: the Assertion() global routine, and the
gPrecondition global constant/variable. The use of these features are the topic of the
discussion below.
Finally, I'm going to start this compilation out of sequence, with my response to a link
from Mr. Cooley of After Hours Software. His link (which is, unfortunately, missing
from the archives) requested an explanation of what assertions are and what they're
good for. My response was actually the end of this thread, but in a zen-like manner not
uncommon in programming, the end is really the beginning.
Please note that italicized comments in brackets [like these] have been added by me for
the purpose of annotation.
5/2/90
POWERUP.ENG Power Up Software,PRT
Dear Mr. Cooley,
Pretty much everything I know about assertions I learned from Bertrand Meyer's